package com.wlyuan.open.scanner.utils.enums.bill;

import com.wlyuan.core.marker.NamedValue;
import com.wlyuan.core.marker.NamedValueMap;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Map;

/**
 * @author lijing
 * @description 对账单状态
 */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum BillStatusEnum implements NamedValue<Integer> {

    DRAFT(0, 0, "草稿"),
    WAIT_CHECK(1, 20, "待审核"),
    ALREADY_CHECK(2, 50, "已对账"),
    MYSELF_REJECTED(30, 30, "本方拒绝"),
    REJECTED(3, 40, "被拒绝"),
    ALREADY_CHECKOUT(4, 60, "已结账"),
    ALREADY_BILL(8, 50, "已对账"),
    CLOSE(32, -1, "已关闭"),
    //兼容16这个状态的数据（16已无用）
    ALREADY_CHECKOUT_OTHER(16, 60, "已结账"),

    WAIT_ME_CHECK(99, 10, "本方待审核"),
    ;

    private final Integer value;
    private final Integer newValue;
    private final String name;

    private static final Map<Integer, BillStatusEnum> MAP = new NamedValueMap<>(BillStatusEnum.class);

    public static BillStatusEnum fromValue(Integer value) {
        return MAP.get(value);
    }

    public static boolean isClose(Integer val) {
        return CLOSE.getValue().equals(val);
    }

    public static boolean isAlready(Integer val) {
        return ALREADY_CHECK.getValue().equals(val) || ALREADY_CHECKOUT.getValue().equals(val) || ALREADY_BILL.getValue().equals(val) || DRAFT.getValue().equals(val) || WAIT_CHECK.getValue().equals(val);
    }

    public static boolean waitAudit(Integer val) {
        return WAIT_CHECK.value.equals(val) || WAIT_ME_CHECK.value.equals(val);
    }

    public static boolean bill(Integer val) {
        return ALREADY_CHECK.getValue().equals(val) || ALREADY_CHECKOUT.getValue().equals(val) || ALREADY_BILL.getValue().equals(val);
    }
}
